<?php

use Swoole\Http\Server;
use Swoole\Process;


if($argc==2){
    $cmd=$argv[1];
    if($cmd=="start"){
        $http = new Swoole\Http\Server("0.0.0.0", 80);

        $http->set(array(
            'worker_num' => 1,
            'daemonize' => false,
        ));
        $http->on('request', function ( $req,$res)   {});
        $http->on('Start', function (Server $server)   {
            $mid= $server->master_pid;
            file_put_contents("./Wolf.pid",$mid);
        });
        $http->start();
    }
    else if($cmd=="stop"){
        $getpid=intval(file_get_contents("./Wolf.pid")); //获取上一次程序运行的 master_id
        if($getpid && trim($getpid)!=0){
            Process::kill($getpid);
        }
    }
    else {
        echo "无效命令".PHP_EOL;
    }
}




